package com.fzrskj.cloud.free.user.utils.diy;

import com.fzrskj.cloud.free.core.enums.DicParamEnum;
import com.fzrskj.cloud.free.dic.bean.DicParam;
import com.fzrskj.cloud.free.dic.utils.DicParamUtils;
import com.fzrskj.cloud.free.sys.dao.SysProductDao;
import ms.core.object.CObject;
import org.apache.commons.collections.map.HashedMap;

import java.util.Map;

/**
 * AgentDiyProductSetUtils.
 *
 * @author zj.
 *         Created on 2020/1/14 0014.
 */
public class AgentDiyProductSetUtils extends CObject {
    /**
     * 代理自定义产品价格溢价率.
     * @param type
     * @param premium
     * @return
     */
    public boolean saveDiyPricePremium(Integer type, Double premium) {
        //更新配置
        DicParamUtils paramUtils = new DicParamUtils();
        Map<String, Object> cdt = new HashedMap();
        cdt.put("paramName", DicParamEnum.DIY_PRICE_PREMIUM.getVal());
        cdt.put("paramType", 1);
        DicParam dicParam = paramUtils.qryDicParams(cdt);
        Map<String, Object> values = new HashedMap();
        values.put("paramValue", premium);
        if (null == dicParam) {
            values.putAll(cdt);
            paramUtils.addDicParam(values);
        } else {
            paramUtils.modDicParam(values, cdt);
        }


        //应用到其他产品
        if (type == 1) {
            SysProductDao productDao = new SysProductDao();
            productDao.setDiyProductPrice(premium);
        }
        return true;
    }
}
